//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __MATH_H__
#define __MATH_H__

#ifdef  __cplusplus
extern "C" {
#endif

/*
 * XOPEN/SVID
 */
#define M_E         2.7182818284590452354       /* e */
#define M_LOG2E     1.4426950408889634074       /* log 2e */
#define M_LOG10E    0.43429448190325182765      /* log 10e */
#define M_LN2       0.69314718055994530942      /* log e2 */
#define M_LN10      2.30258509299404568402      /* log e10 */
#define M_PI        3.14159265358979323846      /* pi */
#define M_PI_2      1.57079632679489661923      /* pi/2 */
#define M_PI_4      0.78539816339744830962      /* pi/4 */
#define M_1_PI      0.31830988618379067154      /* 1/pi */
#define M_2_PI      0.63661977236758134308      /* 2/pi */
#define M_2_SQRTPI  1.12837916709551257390      /* 2/sqrt(pi) */
#define M_SQRT2     1.41421356237309504880      /* sqrt(2) */
#define M_SQRT1_2   0.70710678118654752440      /* 1/sqrt(2) */

#define MAXFLOAT        ((float)3.40282346638528860e+38)
//extern int signgam;

//#if !defined(_XOPEN_SOURCE)
enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix};

#define _LIB_VERSION_TYPE enum fdversion
#define _LIB_VERSION _fdlib_version

/* if global variable _LIB_VERSION is not desirable, one may
 * change the following to be a constant by:
 * #define _LIB_VERSION_TYPE const enum version
 * In that case, after one initializes the value _LIB_VERSION (see
 * s_lib_version.c) during compile time, it cannot be modified
 * in the middle of a program
 */
//extern  _LIB_VERSION_TYPE  _LIB_VERSION;
//
//#define _IEEE_  fdlibm_ieee
//#define _SVID_  fdlibm_svid
//#define _XOPEN_ fdlibm_xopen
//#define _POSIX_ fdlibm_posix

struct exception
{
    int type;       /* exception type - see below */
    char *name;     /* name of function where error occured */
    double arg1;    /* first argument to function */
    double arg2;    /* second argument (if any) to function */
    double retval;  /* value to be returned by function */
};

struct complex
{
    double x,y; /* real and imaginary parts */
};

//#undef vccast
//#define vc(name, value, x1, x2, x3, x4, bexp, xval) ;
//
//#define ic(name, value, bexp, xval)
//const static double name = value;

//#define HUGE  MAXFLOAT

#define HUGE_VAL _infinity

/*
 * set X_TLOSS = pi*2**52, which is possibly defined in <values.h>
 * (one may replace the following line by "#include <values.h>")
 */

#define X_TLOSS         1.41484755040568800000e+16

#define _DOMAIN     1   /* argument domain error */
#define _SING       2   /* argument singularity */
#define _OVERFLOW   3   /* overflow range error */
#define _UNDERFLOW  4   /* underflow range error */
#define _TLOSS      5   /* total loss of precision */
#define _PLOSS      6   /* partial loss of precision */
//#endif                  /* !_XOPEN_SOURCE */
//#endif                  /* !_ANSI_SOURCE && !_POSIX_SOURCE */

//struct DDouble
//{
//    double a;
//    double b;
//};

/* Function prototypes */

//extern   double __exp__E();
//extern   double __log__L();

//typedef  int (cmp_t)(const void *, const void *);
double   __cdecl  floor(double);
double   __cdecl  ceil(double);
double   __cdecl  modf(double, double *);
double   __cdecl  fmod(double, double);

//double   __exp__D (double, double);
//struct   DDouble __log__D(double);

/* Compiler intrinsics */

double   __cdecl  fabs(double);
int      __cdecl  abs(int);
long     __cdecl  labs(long);
double   __cdecl  sin(double);
double   __cdecl  cos(double);
double   __cdecl  tan(double);
double   __cdecl  atan(double);
double   __cdecl  atan2(double, double);
double   __cdecl  exp(double);
double   __cdecl  log(double);
double   __cdecl  log10(double);
double   __cdecl  sqrt(double);
double   __cdecl  pow(double, double);
double   __cdecl  asin(double);
double   __cdecl  acos(double);

double   __cdecl  sinh(double);
double   __cdecl  cosh(double);
double   __cdecl  tanh(double);
double   __cdecl  frexp(double, int *);
double   __cdecl  ldexp(double, int);

double   __cdecl  _logb(double);
double   __cdecl  _copysign(double, double);

double* __cdecl   __p__infinity(void);
#define _infinity (*__p__infinity())

double* __cdecl   __p__nan(void);
#define _NaN (*__p__nan())
//POSIX

#if !defined(_GNUC)
#pragma function(pow, asin, acos, sin, cos, tan, fmod, fabs, abs, labs)
#pragma function(atan, atan2, sinh, cosh, exp, log, log10, sqrt, fabs, tanh)
#endif

#ifdef _EVC
#pragma function(ceil, floor)
#endif

#ifdef  __cplusplus
}
#endif

#endif     // __MATH_H__
